package com.xnyzc.lhy.order.controller.approval;


import com.xnyzc.lhy.common.entity.Rv;
import com.xnyzc.lhy.common.exception.PangException;
import com.xnyzc.lhy.common.penum.EErrorCode;
import com.xnyzc.lhy.common.util.CheckUtil;
import com.xnyzc.lhy.order.entity.param.approval.ApplyUserOperationParam;
import com.xnyzc.lhy.order.entity.param.approval.ApprovalOperationParam;
import com.xnyzc.lhy.order.service.approval.IOaApprovalTaskService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 审批任务表 前端控制器
 * </p>
 *
 * @author huxuekuo
 * @since 2019-08-07
 */
@RestController
@RequestMapping("/core/oaApprovalTask")
public class OaApprovalTaskController {

    @Autowired
    IOaApprovalTaskService iOaApprovalTaskService;

    /**
     * 审批人进行审批操作
     *
     * @param approvalOperationParam
     * @return
     */
    @ApiOperation(value = "审批人进行审批操作", notes = "审批人进行审批操作")
    @PostMapping(value = "/approvalOperation")
    public Rv approvalOperation(@ApiParam(name =
            "approvalOperationParam", value = "审批人进行审批操作") @RequestBody ApprovalOperationParam approvalOperationParam) {
        if (CheckUtil.objIsEmpty(approvalOperationParam)) {
            throw PangException.create(EErrorCode.noData);
        }
        return iOaApprovalTaskService.approvalOperation(approvalOperationParam);
    }

    /**
     * 申请人取消申请或催审批
     *
     * @param applyUserOperationParam
     * @return
     */
    @ApiOperation(value = "申请人取消申请或催审批", notes = "申请人取消申请或催审批")
    @PostMapping(value = "/applyUserOperation")
    public Rv applyUserOperation(@ApiParam(name = "applyUserOperationParam", value = "申请人取消申请或催审批") @RequestBody ApplyUserOperationParam applyUserOperationParam) {
        if (CheckUtil.objIsEmpty(applyUserOperationParam)) {
            throw PangException.create(EErrorCode.noData);
        }
        return iOaApprovalTaskService.applyUserOperation(applyUserOperationParam.getOrderNo(), applyUserOperationParam.getOperationType());
    }


}
